package com.zbkj.crmeb.merchant.admin.controller;


import com.crmeb.core.common.CommonResult;
import com.zbkj.crmeb.chant.request.ActivityProductRequest;
import com.zbkj.crmeb.chant.request.BatchActivityRequest;
import com.zbkj.crmeb.store.response.StoreProductResponse;
import com.zbkj.crmeb.store.service.StoreProductActivityService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

/**
 * <p>
 * 限时活动商品表 前端控制器
 * </p>
 *
 * @author wuzp
 * @since 2022-05-30
 */
@RestController
@RequestMapping("/api/admin/mer/activity/product")
@Api(tags = "商户后台-限时活动商品管理")
public class MerStoreProductActivityController extends AdminBaseController {

    @Autowired
    private StoreProductActivityService storeProductActivityService;

    @ApiOperation("批量移除")
    @DeleteMapping("/batch/delete")
    public CommonResult<Object> batchDelete(@RequestBody @Validated BatchActivityRequest request) {
        return storeProductActivityService.batchDelete(request);
    }

    @ApiOperation("批量加入活动")
    @PostMapping("/batch/add")
    public CommonResult<Object> batchAddActivity(@RequestBody @Validated BatchActivityRequest request,HttpServletRequest servletRequest) {
        return storeProductActivityService.batchAddActivity(request, getMerId(servletRequest));
    }

    @ApiOperation("活动商品详情")
    @GetMapping("/info/{id}")
    public CommonResult<StoreProductResponse> info(@PathVariable Integer id, @ApiParam(required = true)Integer activityId, HttpServletRequest servletRequest) {
        StoreProductResponse storeProductResponse = storeProductActivityService.getByProductId(id,activityId, getMerId(servletRequest));
        return CommonResult.success(storeProductResponse);
    }

    @ApiOperation(value = "修改活动商品")
    @PostMapping(value = "/update")
    public CommonResult<String> updateActivityProduct(@RequestBody @Validated ActivityProductRequest request, HttpServletRequest servletRequest) {
        return storeProductActivityService.updateActivityProduct(request, getMerId(servletRequest))
                ? CommonResult.success() : CommonResult.failed();
    }

}

